#include "Logger.hpp"
#include "UdpSever.hpp"
#include "User.hpp"
#include <memory>

using namespace LogMudule;

int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        LOG(LogLevel::FATAL) << argv[0] << "severport";
        Die(USAGE_ERR);
    }

    uint16_t port = std::stoi(argv[1]);

    // 用户管理模块
    std::shared_ptr<UserManager> umsptr = std::make_shared<UserManager>();

    std::unique_ptr<UdpSever> sev_ptr = std::make_unique<UdpSever>(port);

    sev_ptr->RegisterTask([&umsptr](InetAddr &id){ umsptr->AddUser(id); },
                          [&umsptr](InetAddr &id){ umsptr->DelUser(id); },
                          [&umsptr](int sockfd, const std::string &message)
                          { umsptr->Route(sockfd, message); });

    sev_ptr->SeverInit();
    sev_ptr->Start();

    return 0;
}
